#!/usr/bin/make -f
#export DH_VERBOSE=1
export QUILT_PATCHES = debian/patches

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

build: build-stamp

build-stamp: patch
	dh_testdir
	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --prefix=$$(pwd)/debian/dvipng/usr
	$(MAKE) dvipng
	$(MAKE) docs
# Using upstreams manpage 
#	/usr/bin/docbook-to-man debian/dvipng.sgml > dvipng.1
	touch build-stamp

clean: clean-stamp 

clean-stamp:
	dh_testdir
	dh_testroot
	rm -f build-stamp 
	-$(MAKE) clean
	rm -f Makefile config.h
	rm -f config.status config.log config.cache c-auto.h
	rm -f config.sub config.status
	dh_clean 

patch: patch-stamp
patch-stamp:
	-quilt push -a

unpatch:
	-quilt pop -a
	rm -f patch-stamp

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs -v
	dh_install -v
	dh_link -v

# Build architecture-independent files here.
binary-indep: build install

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog upstream
	dh_installdocs README RELEASE
	dh_install
	dh_installinfo dvipng.info
	dh_installman dvipng.1
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install 
